<script setup lang="ts">
import useNotificationStore from '@/store/modules/notification'

defineOptions({
  name: 'Notification',
})

const notificationStore = useNotificationStore()

const activeName = ref('message')
</script>

<template>
  <el-tabs v-model="activeName" class="notification">
    <el-tab-pane :label="`消息 ${notificationStore.message > 0 ? `(${notificationStore.message})` : ''}`" name="message" class="container">
      <el-scrollbar max-height="300px" class="list">
        <div class="item">
          <svg-icon name="ri:mail-fill" />
          <div class="info">
            <div class="title">
              你收到了 8 份日报
            </div>
            <div class="date">
              2020-10-10 10:00:00
            </div>
          </div>
        </div>
        <div class="item">
          <svg-icon name="ri:service-fill" class="service" />
          <div class="info">
            <div class="title">
              你收到了 3 位同事的好友申请，请及时处理
            </div>
            <div class="date">
              2020-10-10 10:00:00
            </div>
          </div>
        </div>
        <div class="item">
          <svg-icon name="ri:file-edit-fill" class="file-edit" />
          <div class="info">
            <div class="title">
              你有 3 份合同待审批
            </div>
            <div class="date">
              2020-10-10 10:00:00
            </div>
          </div>
        </div>
        <div class="item">
          <svg-icon name="ri:mail-fill" />
          <div class="info">
            <div class="title">
              你收到了 8 份日报
            </div>
            <div class="date">
              2020-10-10 10:00:00
            </div>
          </div>
        </div>
        <div class="item">
          <svg-icon name="ri:service-fill" class="service" />
          <div class="info">
            <div class="title">
              你收到了 3 位同事的好友申请，请及时处理
            </div>
            <div class="date">
              2020-10-10 10:00:00
            </div>
          </div>
        </div>
      </el-scrollbar>
      <router-link v-slot="{ navigate }" :to="{ name: 'personalNotification' }" custom>
        <div class="more" @click="navigate">
          进入消息列表
        </div>
      </router-link>
    </el-tab-pane>
    <el-tab-pane :label="`待办 ${notificationStore.todo > 0 ? `(${notificationStore.todo})` : ''}`" name="todo" class="container">
      <el-scrollbar max-height="300px" class="list">
        <div class="empty">
          暂时没有新待办
        </div>
      </el-scrollbar>
      <router-link v-slot="{ navigate }" :to="{ name: 'personalNotification' }" custom>
        <div class="more" @click="navigate">
          进入待办列表
        </div>
      </router-link>
    </el-tab-pane>
  </el-tabs>
</template>

<style lang="scss" scoped>
.notification {
  margin-top: -10px;

  :deep(.el-tabs__header) {
    margin-bottom: 0;
  }

  :deep(.el-tabs__nav-scroll) {
    text-align: center;

    .el-tabs__nav {
      display: inline-flex;
      margin: 0 auto;
      float: none;

      .el-tabs__item {
        padding: 0 12px;
      }
    }
  }
}

.container {
  .list {
    :deep(.el-scrollbar__wrap) {
      overscroll-behavior: contain;
    }

    .item {
      display: flex;
      align-items: flex-start;
      padding: 15px 10px;
      transition: 0.3s;
      border-bottom: 1px solid var(--el-border-color);
      cursor: pointer;

      &:hover {
        background-color: var(--el-fill-color);
      }

      &:last-child {
        border-bottom: unset;
      }

      .icon {
        flex: none;
        margin-right: 10px;
        width: 2em;
        height: 2em;
        border-radius: 50%;
        color: #fff;
        background-color: var(--el-color-primary);

        &.service {
          background-color: var(--el-color-success);
        }

        &.file-edit {
          background-color: var(--el-color-warning);
        }

        &.bug {
          background-color: var(--el-color-danger);
        }
      }

      .info {
        .title {
          font-size: 14px;
          line-height: 1.5;

          @include text-overflow(2);
        }

        .date {
          margin-top: 5px;
          font-size: 12px;
          color: var(--el-text-color-secondary);
        }
      }
    }

    .empty {
      padding: 30px 0;
      text-align: center;
      color: var(--el-text-color-placeholder);
    }
  }

  .more {
    padding: 15px 0;
    margin-bottom: -10px;
    text-align: center;
    color: var(--el-text-color-secondary);
    border-top: 1px solid var(--el-border-color);
    cursor: pointer;
  }
}
</style>
